package app

import (
	"chatgpt/helper/code"
	"chatgpt/logq"
	"chatgpt/plugin/rpcx"
	"chatgpt/services/datasrv/sqlhelper"
	"context"
)

func (self AppApi) ProductSelect(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ProductSelect", req, res)
	if err != nil {
		logq.Error("DataSrv.Product.Select err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self AppApi) ProductSave(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ProductSave", req, res)
	if err != nil {
		logq.Error("DataSrv.Product.Save err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self AppApi) ProductTotal(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ProductTotal", req, res)
	if err != nil {
		logq.Error("DataSrv.Product.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self AppApi) ProductFirst(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ProductFirst", req, res)
	if err != nil {
		logq.Error("DataSrv.Product.Total err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}

func (self AppApi) ProductDelete(ctx context.Context, req *sqlhelper.ReqWhere, res *sqlhelper.ResWhere) code.CODENO {
	client := rpcx.DataSrv.GetRand("AppApi")
	err := client.Call(ctx, "ProductDelete", req, res)
	if err != nil {
		logq.Error("DataSrv.Product.Delete err:", err)
		return code.DATA_CALL_ERROR
	}
	return res.MsgCode
}
